1
1
pub ( crate ) mod encode;
2
+ mod serde;
2
3
3
4
use std:: collections:: BTreeSet ;
4
5
use std:: collections:: hash_map:: Entry ;
5
6
use std:: path:: Path ;
6
7
8
+ use :: serde:: de:: { self , Deserializer , Error as _} ;
9
+ use :: serde:: ser:: { SerializeSeq , Serializer } ;
10
+ use :: serde:: { Deserialize , Serialize } ;
7
11
use rustc_ast:: join_path_syms;
8
12
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet , FxIndexMap } ;
9
13
use rustc_hir:: attrs:: AttributeKind ;
@@ -12,9 +16,6 @@ use rustc_middle::ty::TyCtxt;
12
16
use rustc_span:: def_id:: DefId ;
13
17
use rustc_span:: sym;
14
18
use rustc_span:: symbol:: { Symbol , kw} ;
15
- use serde:: de:: { self , Deserializer , Error as _} ;
16
- use serde:: ser:: { SerializeSeq , Serializer } ;
17
- use serde:: { Deserialize , Serialize } ;
18
19
use stringdex:: internals as stringdex_internals;
19
20
use thin_vec:: ThinVec ;
20
21
use tracing:: instrument;
@@ -34,7 +35,7 @@ pub(crate) struct SerializedSearchIndex {
34
35
path_data : Vec < Option < PathData > > ,
35
36
entry_data : Vec < Option < EntryData > > ,
36
37
descs : Vec < String > ,
37
- function_data : Vec < Option < FunctionData > > ,
38
+ function_data : Vec < Option < IndexItemFunctionType > > ,
38
39
alias_pointers : Vec < Option < usize > > ,
39
40
// inverted index for concrete types and generics
40
41
type_data : Vec < Option < TypeData > > ,
@@ -61,7 +62,7 @@ impl SerializedSearchIndex {
61
62
let mut path_data: Vec < Option < PathData > > = Vec :: new ( ) ;
62
63
let mut entry_data: Vec < Option < EntryData > > = Vec :: new ( ) ;
63
64
let mut descs: Vec < String > = Vec :: new ( ) ;
64
- let mut function_data: Vec < Option < FunctionData > > = Vec :: new ( ) ;
65
+ let mut function_data: Vec < Option < IndexItemFunctionType > > = Vec :: new ( ) ;
65
66
let mut type_data: Vec < Option < TypeData > > = Vec :: new ( ) ;
66
67
let mut alias_pointers: Vec < Option < usize > > = Vec :: new ( ) ;
67
68
@@ -207,7 +208,7 @@ impl SerializedSearchIndex {
207
208
path_data : Option < PathData > ,
208
209
entry_data : Option < EntryData > ,
209
210
desc : String ,
210
- function_data : Option < FunctionData > ,
211
+ function_data : Option < IndexItemFunctionType > ,
211
212
type_data : Option < TypeData > ,
212
213
alias_pointer : Option < usize > ,
213
214
) -> usize {
@@ -446,73 +447,62 @@ impl SerializedSearchIndex {
446
447
..other_entry_data. clone ( )
447
448
} ) ,
448
449
other. descs [ other_entryid] . clone ( ) ,
449
- other. function_data [ other_entryid] . as_ref ( ) . map ( |function_data| FunctionData {
450
- function_signature : {
451
- let ( mut func, _offset) =
452
- IndexItemFunctionType :: read_from_string_without_param_names (
453
- function_data. function_signature . as_bytes ( ) ,
454
- ) ;
455
- fn map_fn_sig_item (
456
- map_other_pathid_to_self_pathid : & mut Vec < usize > ,
457
- ty : & mut RenderType ,
458
- ) {
459
- match ty. id {
460
- None => { }
461
- Some ( RenderTypeId :: Index ( generic) ) if generic < 0 => { }
462
- Some ( RenderTypeId :: Index ( id) ) => {
463
- let id = usize:: try_from ( id) . unwrap ( ) ;
464
- let id = map_other_pathid_to_self_pathid[ id] ;
465
- assert ! ( id != !0 ) ;
466
- ty. id =
467
- Some ( RenderTypeId :: Index ( isize:: try_from ( id) . unwrap ( ) ) ) ;
468
- }
469
- _ => unreachable ! ( ) ,
450
+ other. function_data [ other_entryid] . clone ( ) . map ( |mut func| {
451
+ fn map_fn_sig_item (
452
+ map_other_pathid_to_self_pathid : & mut Vec < usize > ,
453
+ ty : & mut RenderType ,
454
+ ) {
455
+ match ty. id {
456
+ None => { }
457
+ Some ( RenderTypeId :: Index ( generic) ) if generic < 0 => { }
458
+ Some ( RenderTypeId :: Index ( id) ) => {
459
+ let id = usize:: try_from ( id) . unwrap ( ) ;
460
+ let id = map_other_pathid_to_self_pathid[ id] ;
461
+ assert ! ( id != !0 ) ;
462
+ ty. id = Some ( RenderTypeId :: Index ( isize:: try_from ( id) . unwrap ( ) ) ) ;
470
463
}
471
- if let Some ( generics) = & mut ty. generics {
472
- for generic in generics {
473
- map_fn_sig_item ( map_other_pathid_to_self_pathid, generic) ;
474
- }
464
+ _ => unreachable ! ( ) ,
465
+ }
466
+ if let Some ( generics) = & mut ty. generics {
467
+ for generic in generics {
468
+ map_fn_sig_item ( map_other_pathid_to_self_pathid, generic) ;
475
469
}
476
- if let Some ( bindings) = & mut ty. bindings {
477
- for ( param, constraints) in bindings {
478
- * param = match * param {
479
- param @ RenderTypeId :: Index ( generic) if generic < 0 => {
480
- param
481
- }
482
- RenderTypeId :: Index ( id) => {
483
- let id = usize:: try_from ( id) . unwrap ( ) ;
484
- let id = map_other_pathid_to_self_pathid[ id] ;
485
- assert ! ( id != !0 ) ;
486
- RenderTypeId :: Index ( isize:: try_from ( id) . unwrap ( ) )
487
- }
488
- _ => unreachable ! ( ) ,
489
- } ;
490
- for constraint in constraints {
491
- map_fn_sig_item (
492
- map_other_pathid_to_self_pathid,
493
- constraint,
494
- ) ;
470
+ }
471
+ if let Some ( bindings) = & mut ty. bindings {
472
+ for ( param, constraints) in bindings {
473
+ * param = match * param {
474
+ param @ RenderTypeId :: Index ( generic) if generic < 0 => {
475
+ param
476
+ }
477
+ RenderTypeId :: Index ( id) => {
478
+ let id = usize:: try_from ( id) . unwrap ( ) ;
479
+ let id = map_other_pathid_to_self_pathid[ id] ;
480
+ assert ! ( id != !0 ) ;
481
+ RenderTypeId :: Index ( isize:: try_from ( id) . unwrap ( ) )
495
482
}
483
+ _ => unreachable ! ( ) ,
484
+ } ;
485
+ for constraint in constraints {
486
+ map_fn_sig_item (
487
+ map_other_pathid_to_self_pathid,
488
+ constraint,
489
+ ) ;
496
490
}
497
491
}
498
492
}
499
- for input in & mut func . inputs {
500
- map_fn_sig_item ( & mut map_other_pathid_to_self_pathid , input ) ;
501
- }
502
- for output in & mut func . output {
503
- map_fn_sig_item ( & mut map_other_pathid_to_self_pathid , output) ;
504
- }
505
- for clause in & mut func . where_clause {
506
- for entry in clause {
507
- map_fn_sig_item ( & mut map_other_pathid_to_self_pathid , entry ) ;
508
- }
493
+ }
494
+ for input in & mut func . inputs {
495
+ map_fn_sig_item ( & mut map_other_pathid_to_self_pathid , input ) ;
496
+ }
497
+ for output in & mut func . output {
498
+ map_fn_sig_item ( & mut map_other_pathid_to_self_pathid , output ) ;
499
+ }
500
+ for clause in & mut func . where_clause {
501
+ for entry in clause {
502
+ map_fn_sig_item ( & mut map_other_pathid_to_self_pathid , entry ) ;
509
503
}
510
- let mut result =
511
- String :: with_capacity ( function_data. function_signature . len ( ) ) ;
512
- func. write_to_string_without_param_names ( & mut result) ;
513
- result
514
- } ,
515
- param_names : function_data. param_names . clone ( ) ,
504
+ }
505
+ func
516
506
} ) ,
517
507
other. type_data [ other_entryid] . as_ref ( ) . map ( |type_data| TypeData {
518
508
inverted_function_inputs_index : type_data
@@ -626,69 +616,55 @@ impl SerializedSearchIndex {
626
616
} ,
627
617
) ,
628
618
self . descs [ id] . clone ( ) ,
629
- self . function_data [ id] . as_ref ( ) . map (
630
- |FunctionData { function_signature, param_names } | FunctionData {
631
- function_signature : {
632
- let ( mut func, _offset) =
633
- IndexItemFunctionType :: read_from_string_without_param_names (
634
- function_signature. as_bytes ( ) ,
635
- ) ;
636
- fn map_fn_sig_item ( map : & FxHashMap < usize , usize > , ty : & mut RenderType ) {
637
- match ty. id {
638
- None => { }
639
- Some ( RenderTypeId :: Index ( generic) ) if generic < 0 => { }
640
- Some ( RenderTypeId :: Index ( id) ) => {
619
+ self . function_data [ id] . clone ( ) . map ( |mut func| {
620
+ fn map_fn_sig_item ( map : & FxHashMap < usize , usize > , ty : & mut RenderType ) {
621
+ match ty. id {
622
+ None => { }
623
+ Some ( RenderTypeId :: Index ( generic) ) if generic < 0 => { }
624
+ Some ( RenderTypeId :: Index ( id) ) => {
625
+ let id = usize:: try_from ( id) . unwrap ( ) ;
626
+ let id = * map. get ( & id) . unwrap ( ) ;
627
+ assert ! ( id != !0 ) ;
628
+ ty. id = Some ( RenderTypeId :: Index ( isize:: try_from ( id) . unwrap ( ) ) ) ;
629
+ }
630
+ _ => unreachable ! ( ) ,
631
+ }
632
+ if let Some ( generics) = & mut ty. generics {
633
+ for generic in generics {
634
+ map_fn_sig_item ( map, generic) ;
635
+ }
636
+ }
637
+ if let Some ( bindings) = & mut ty. bindings {
638
+ for ( param, constraints) in bindings {
639
+ * param = match * param {
640
+ param @ RenderTypeId :: Index ( generic) if generic < 0 => param,
641
+ RenderTypeId :: Index ( id) => {
641
642
let id = usize:: try_from ( id) . unwrap ( ) ;
642
643
let id = * map. get ( & id) . unwrap ( ) ;
643
644
assert ! ( id != !0 ) ;
644
- ty. id =
645
- Some ( RenderTypeId :: Index ( isize:: try_from ( id) . unwrap ( ) ) ) ;
645
+ RenderTypeId :: Index ( isize:: try_from ( id) . unwrap ( ) )
646
646
}
647
647
_ => unreachable ! ( ) ,
648
+ } ;
649
+ for constraint in constraints {
650
+ map_fn_sig_item ( map, constraint) ;
648
651
}
649
- if let Some ( generics) = & mut ty. generics {
650
- for generic in generics {
651
- map_fn_sig_item ( map, generic) ;
652
- }
653
- }
654
- if let Some ( bindings) = & mut ty. bindings {
655
- for ( param, constraints) in bindings {
656
- * param = match * param {
657
- param @ RenderTypeId :: Index ( generic) if generic < 0 => {
658
- param
659
- }
660
- RenderTypeId :: Index ( id) => {
661
- let id = usize:: try_from ( id) . unwrap ( ) ;
662
- let id = * map. get ( & id) . unwrap ( ) ;
663
- assert ! ( id != !0 ) ;
664
- RenderTypeId :: Index ( isize:: try_from ( id) . unwrap ( ) )
665
- }
666
- _ => unreachable ! ( ) ,
667
- } ;
668
- for constraint in constraints {
669
- map_fn_sig_item ( map, constraint) ;
670
- }
671
- }
672
- }
673
- }
674
- for input in & mut func. inputs {
675
- map_fn_sig_item ( & map, input) ;
676
- }
677
- for output in & mut func. output {
678
- map_fn_sig_item ( & map, output) ;
679
652
}
680
- for clause in & mut func. where_clause {
681
- for entry in clause {
682
- map_fn_sig_item ( & map, entry) ;
683
- }
684
- }
685
- let mut result = String :: with_capacity ( function_signature. len ( ) ) ;
686
- func. write_to_string_without_param_names ( & mut result) ;
687
- result
688
- } ,
689
- param_names : param_names. clone ( ) ,
690
- } ,
691
- ) ,
653
+ }
654
+ }
655
+ for input in & mut func. inputs {
656
+ map_fn_sig_item ( & map, input) ;
657
+ }
658
+ for output in & mut func. output {
659
+ map_fn_sig_item ( & map, output) ;
660
+ }
661
+ for clause in & mut func. where_clause {
662
+ for entry in clause {
663
+ map_fn_sig_item ( & map, entry) ;
664
+ }
665
+ }
666
+ func
667
+ } ) ,
692
668
self . type_data [ id] . as_ref ( ) . map (
693
669
|TypeData {
694
670
search_unbox,
@@ -1259,48 +1235,6 @@ impl<'de> Deserialize<'de> for SerializedOptional32 {
1259
1235
}
1260
1236
}
1261
1237
1262
- #[ derive( Clone , Debug ) ]
1263
- pub struct FunctionData {
1264
- function_signature : String ,
1265
- param_names : Vec < String > ,
1266
- }
1267
-
1268
- impl Serialize for FunctionData {
1269
- fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
1270
- where
1271
- S : Serializer ,
1272
- {
1273
- let mut seq = serializer. serialize_seq ( None ) ?;
1274
- seq. serialize_element ( & self . function_signature ) ?;
1275
- seq. serialize_element ( & self . param_names ) ?;
1276
- seq. end ( )
1277
- }
1278
- }
1279
-
1280
- impl < ' de > Deserialize < ' de > for FunctionData {
1281
- fn deserialize < D > ( deserializer : D ) -> Result < FunctionData , D :: Error >
1282
- where
1283
- D : Deserializer < ' de > ,
1284
- {
1285
- struct FunctionDataVisitor ;
1286
- impl < ' de > de:: Visitor < ' de > for FunctionDataVisitor {
1287
- type Value = FunctionData ;
1288
- fn expecting ( & self , formatter : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1289
- write ! ( formatter, "fn data" )
1290
- }
1291
- fn visit_seq < A : de:: SeqAccess < ' de > > ( self , mut v : A ) -> Result < FunctionData , A :: Error > {
1292
- let function_signature: String = v
1293
- . next_element ( ) ?
1294
- . ok_or_else ( || A :: Error :: missing_field ( "function_signature" ) ) ?;
1295
- let param_names: Vec < String > =
1296
- v. next_element ( ) ?. ok_or_else ( || A :: Error :: missing_field ( "param_names" ) ) ?;
1297
- Ok ( FunctionData { function_signature, param_names } )
1298
- }
1299
- }
1300
- deserializer. deserialize_any ( FunctionDataVisitor )
1301
- }
1302
- }
1303
-
1304
1238
/// Builds the search index from the collected metadata
1305
1239
pub ( crate ) fn build_index (
1306
1240
krate : & clean:: Crate ,
@@ -1927,18 +1861,7 @@ pub(crate) fn build_index(
1927
1861
// because the postings list has to fill in an empty array for each
1928
1862
// unoccupied size.
1929
1863
if item. ty . is_fn_like ( ) { 0 } else { 16 } ;
1930
- serialized_index. function_data [ new_entry_id] = Some ( FunctionData {
1931
- function_signature : {
1932
- let mut function_signature = String :: new ( ) ;
1933
- search_type. write_to_string_without_param_names ( & mut function_signature) ;
1934
- function_signature
1935
- } ,
1936
- param_names : search_type
1937
- . param_names
1938
- . iter ( )
1939
- . map ( |sym| sym. map ( |sym| sym. to_string ( ) ) . unwrap_or ( String :: new ( ) ) )
1940
- . collect :: < Vec < String > > ( ) ,
1941
- } ) ;
1864
+ serialized_index. function_data [ new_entry_id] = Some ( search_type. clone ( ) ) ;
1942
1865
for index in used_in_function_inputs {
1943
1866
let postings = if index >= 0 {
1944
1867
assert ! ( serialized_index. path_data[ index as usize ] . is_some( ) ) ;
0 commit comments