@@ -11,7 +11,6 @@ use std::{fmt, mem, ops, str::FromStr};
11
11
use cfg:: CfgOptions ;
12
12
use la_arena:: { Arena , Idx , RawIdx } ;
13
13
use rustc_hash:: { FxHashMap , FxHashSet } ;
14
- use semver:: Version ;
15
14
use syntax:: SmolStr ;
16
15
use triomphe:: Arc ;
17
16
use vfs:: { file_set:: FileSet , AbsPathBuf , AnchoredPath , FileId , VfsPath } ;
@@ -292,16 +291,11 @@ pub struct CrateData {
292
291
pub dependencies : Vec < Dependency > ,
293
292
pub origin : CrateOrigin ,
294
293
pub is_proc_macro : bool ,
295
- // FIXME: These things should not be per crate! These are more per workspace crate graph level
296
- // things. This info does need to be somewhat present though as to prevent deduplication from
297
- // happening across different workspaces with different layouts.
298
- pub target_layout : TargetLayoutLoadResult ,
299
- pub toolchain : Option < Version > ,
300
294
}
301
295
302
296
impl CrateData {
303
297
/// Check if [`other`] is almost equal to [`self`] ignoring `CrateOrigin` value.
304
- pub fn eq_ignoring_origin_and_deps ( & self , other : & CrateData , ignore_dev_deps : bool ) -> bool {
298
+ fn eq_ignoring_origin_and_deps ( & self , other : & CrateData , ignore_dev_deps : bool ) -> bool {
305
299
// This method has some obscure bits. These are mostly there to be compliant with
306
300
// some patches. References to the patches are given.
307
301
if self . root_file_id != other. root_file_id {
@@ -353,10 +347,6 @@ impl CrateData {
353
347
354
348
slf_deps. eq ( other_deps)
355
349
}
356
-
357
- pub fn channel ( & self ) -> Option < ReleaseChannel > {
358
- self . toolchain . as_ref ( ) . and_then ( |v| ReleaseChannel :: from_str ( & v. pre ) )
359
- }
360
350
}
361
351
362
352
#[ derive( Debug , Clone , Copy , PartialEq , Eq , PartialOrd , Ord , Hash ) ]
@@ -439,8 +429,6 @@ impl CrateGraph {
439
429
env : Env ,
440
430
is_proc_macro : bool ,
441
431
origin : CrateOrigin ,
442
- target_layout : Result < Arc < str > , Arc < str > > ,
443
- toolchain : Option < Version > ,
444
432
) -> CrateId {
445
433
let data = CrateData {
446
434
root_file_id,
@@ -452,9 +440,7 @@ impl CrateGraph {
452
440
env,
453
441
dependencies : Vec :: new ( ) ,
454
442
origin,
455
- target_layout,
456
443
is_proc_macro,
457
- toolchain,
458
444
} ;
459
445
self . arena . alloc ( data)
460
446
}
@@ -524,6 +510,10 @@ impl CrateGraph {
524
510
self . arena . is_empty ( )
525
511
}
526
512
513
+ pub fn len ( & self ) -> usize {
514
+ self . arena . len ( )
515
+ }
516
+
527
517
pub fn iter ( & self ) -> impl Iterator < Item = CrateId > + ' _ {
528
518
self . arena . iter ( ) . map ( |( idx, _) | idx)
529
519
}
@@ -624,13 +614,16 @@ impl CrateGraph {
624
614
///
625
615
/// This will deduplicate the crates of the graph where possible.
626
616
/// Note that for deduplication to fully work, `self`'s crate dependencies must be sorted by crate id.
627
- /// If the crate dependencies were sorted, the resulting graph from this `extend` call will also have the crate dependencies sorted.
617
+ /// If the crate dependencies were sorted, the resulting graph from this `extend` call will also
618
+ /// have the crate dependencies sorted.
619
+ ///
620
+ /// Returns a mapping from `other`'s crate ids to the new crate ids in `self`.
628
621
pub fn extend (
629
622
& mut self ,
630
623
mut other : CrateGraph ,
631
624
proc_macros : & mut ProcMacroPaths ,
632
- on_finished : impl FnOnce ( & FxHashMap < CrateId , CrateId > ) ,
633
- ) {
625
+ may_merge : impl Fn ( ( CrateId , & CrateData ) , ( CrateId , & CrateData ) ) -> bool ,
626
+ ) -> FxHashMap < CrateId , CrateId > {
634
627
let topo = other. crates_in_topological_order ( ) ;
635
628
let mut id_map: FxHashMap < CrateId , CrateId > = FxHashMap :: default ( ) ;
636
629
for topo in topo {
@@ -639,6 +632,10 @@ impl CrateGraph {
639
632
crate_data. dependencies . iter_mut ( ) . for_each ( |dep| dep. crate_id = id_map[ & dep. crate_id ] ) ;
640
633
crate_data. dependencies . sort_by_key ( |dep| dep. crate_id ) ;
641
634
let res = self . arena . iter ( ) . find_map ( |( id, data) | {
635
+ if !may_merge ( ( id, & data) , ( topo, & crate_data) ) {
636
+ return None ;
637
+ }
638
+
642
639
match ( & data. origin , & crate_data. origin ) {
643
640
( a, b) if a == b => {
644
641
if data. eq_ignoring_origin_and_deps ( crate_data, false ) {
@@ -663,8 +660,7 @@ impl CrateGraph {
663
660
None
664
661
} ) ;
665
662
666
- if let Some ( ( res, should_update_lib_to_local) ) = res {
667
- id_map. insert ( topo, res) ;
663
+ let new_id = if let Some ( ( res, should_update_lib_to_local) ) = res {
668
664
if should_update_lib_to_local {
669
665
assert ! ( self . arena[ res] . origin. is_lib( ) ) ;
670
666
assert ! ( crate_data. origin. is_local( ) ) ;
@@ -673,16 +669,17 @@ impl CrateGraph {
673
669
// Move local's dev dependencies into the newly-local-formerly-lib crate.
674
670
self . arena [ res] . dependencies = crate_data. dependencies . clone ( ) ;
675
671
}
672
+ res
676
673
} else {
677
- let id = self . arena . alloc ( crate_data. clone ( ) ) ;
678
- id_map . insert ( topo , id ) ;
679
- }
674
+ self . arena . alloc ( crate_data. clone ( ) )
675
+ } ;
676
+ id_map . insert ( topo , new_id ) ;
680
677
}
681
678
682
679
* proc_macros =
683
680
mem:: take ( proc_macros) . into_iter ( ) . map ( |( id, macros) | ( id_map[ & id] , macros) ) . collect ( ) ;
684
681
685
- on_finished ( & id_map) ;
682
+ id_map
686
683
}
687
684
688
685
fn find_path (
@@ -889,8 +886,6 @@ mod tests {
889
886
Env :: default ( ) ,
890
887
false ,
891
888
CrateOrigin :: Local { repo : None , name : None } ,
892
- Err ( "" . into ( ) ) ,
893
- None ,
894
889
) ;
895
890
let crate2 = graph. add_crate_root (
896
891
FileId :: from_raw ( 2u32 ) ,
@@ -902,8 +897,6 @@ mod tests {
902
897
Env :: default ( ) ,
903
898
false ,
904
899
CrateOrigin :: Local { repo : None , name : None } ,
905
- Err ( "" . into ( ) ) ,
906
- None ,
907
900
) ;
908
901
let crate3 = graph. add_crate_root (
909
902
FileId :: from_raw ( 3u32 ) ,
@@ -915,8 +908,6 @@ mod tests {
915
908
Env :: default ( ) ,
916
909
false ,
917
910
CrateOrigin :: Local { repo : None , name : None } ,
918
- Err ( "" . into ( ) ) ,
919
- None ,
920
911
) ;
921
912
assert ! ( graph
922
913
. add_dep(
@@ -951,8 +942,6 @@ mod tests {
951
942
Env :: default ( ) ,
952
943
false ,
953
944
CrateOrigin :: Local { repo : None , name : None } ,
954
- Err ( "" . into ( ) ) ,
955
- None ,
956
945
) ;
957
946
let crate2 = graph. add_crate_root (
958
947
FileId :: from_raw ( 2u32 ) ,
@@ -964,8 +953,6 @@ mod tests {
964
953
Env :: default ( ) ,
965
954
false ,
966
955
CrateOrigin :: Local { repo : None , name : None } ,
967
- Err ( "" . into ( ) ) ,
968
- None ,
969
956
) ;
970
957
assert ! ( graph
971
958
. add_dep(
@@ -994,8 +981,6 @@ mod tests {
994
981
Env :: default ( ) ,
995
982
false ,
996
983
CrateOrigin :: Local { repo : None , name : None } ,
997
- Err ( "" . into ( ) ) ,
998
- None ,
999
984
) ;
1000
985
let crate2 = graph. add_crate_root (
1001
986
FileId :: from_raw ( 2u32 ) ,
@@ -1007,8 +992,6 @@ mod tests {
1007
992
Env :: default ( ) ,
1008
993
false ,
1009
994
CrateOrigin :: Local { repo : None , name : None } ,
1010
- Err ( "" . into ( ) ) ,
1011
- None ,
1012
995
) ;
1013
996
let crate3 = graph. add_crate_root (
1014
997
FileId :: from_raw ( 3u32 ) ,
@@ -1020,8 +1003,6 @@ mod tests {
1020
1003
Env :: default ( ) ,
1021
1004
false ,
1022
1005
CrateOrigin :: Local { repo : None , name : None } ,
1023
- Err ( "" . into ( ) ) ,
1024
- None ,
1025
1006
) ;
1026
1007
assert ! ( graph
1027
1008
. add_dep(
@@ -1050,8 +1031,6 @@ mod tests {
1050
1031
Env :: default ( ) ,
1051
1032
false ,
1052
1033
CrateOrigin :: Local { repo : None , name : None } ,
1053
- Err ( "" . into ( ) ) ,
1054
- None ,
1055
1034
) ;
1056
1035
let crate2 = graph. add_crate_root (
1057
1036
FileId :: from_raw ( 2u32 ) ,
@@ -1063,8 +1042,6 @@ mod tests {
1063
1042
Env :: default ( ) ,
1064
1043
false ,
1065
1044
CrateOrigin :: Local { repo : None , name : None } ,
1066
- Err ( "" . into ( ) ) ,
1067
- None ,
1068
1045
) ;
1069
1046
assert ! ( graph
1070
1047
. add_dep(
0 commit comments