@@ -40,6 +40,7 @@ use crate::DefineDef;
40
40
use crate :: File ;
41
41
use crate :: FormIdx ;
42
42
use crate :: FunctionDef ;
43
+ use crate :: FunctionId ;
43
44
use crate :: InFile ;
44
45
use crate :: MacroName ;
45
46
use crate :: Name ;
@@ -66,6 +67,7 @@ pub struct DefMap {
66
67
macros : FxHashMap < MacroName , DefineDef > ,
67
68
export_all : bool ,
68
69
pub parse_transform : bool ,
70
+ function_by_function_id : FxHashMap < FunctionId , FunctionDef > ,
69
71
}
70
72
71
73
#[ derive( Debug , Clone , PartialEq , Eq , Default ) ]
@@ -122,18 +124,20 @@ impl DefMap {
122
124
match form {
123
125
FormIdx :: Function ( idx) => {
124
126
let function = form_list[ idx] . clone ( ) ;
125
- def_map. functions . insert (
126
- function. name . clone ( ) ,
127
- FunctionDef {
128
- file,
129
- exported : false ,
130
- deprecated : false ,
131
- deprecated_desc : None ,
132
- module : module. clone ( ) ,
133
- function,
134
- function_id : idx,
135
- } ,
136
- ) ;
127
+ let fun_name = & function. name . clone ( ) ;
128
+ let function_def = FunctionDef {
129
+ file,
130
+ exported : false ,
131
+ deprecated : false ,
132
+ deprecated_desc : None ,
133
+ module : module. clone ( ) ,
134
+ function,
135
+ function_id : idx,
136
+ } ;
137
+ def_map
138
+ . functions
139
+ . insert ( fun_name. clone ( ) , function_def. clone ( ) ) ;
140
+ def_map. function_by_function_id . insert ( idx, function_def) ;
137
141
}
138
142
FormIdx :: Export ( idx) => {
139
143
for export_id in form_list[ idx] . entries . clone ( ) {
@@ -544,6 +548,7 @@ impl DefMap {
544
548
export_all : _,
545
549
parse_transform : _,
546
550
optional_callbacks,
551
+ function_by_function_id : function_by_form_id,
547
552
} = self ;
548
553
549
554
included. shrink_to_fit ( ) ;
@@ -558,6 +563,7 @@ impl DefMap {
558
563
callbacks. shrink_to_fit ( ) ;
559
564
macros. shrink_to_fit ( ) ;
560
565
deprecated. shrink_to_fit ( ) ;
566
+ function_by_form_id. shrink_to_fit ( ) ;
561
567
}
562
568
}
563
569
@@ -582,7 +588,35 @@ mod tests {
582
588
format ! (
583
589
"fun {} exported: {}" ,
584
590
def. function. name,
585
- def. exported && def_map. exported_functions. contains( & def. function. name)
591
+ def. exported && def_map. exported_functions. contains( & def. function. name) ,
592
+ )
593
+ } )
594
+ . chain ( def_map. types . values ( ) . map ( |def| match & def. type_alias {
595
+ TypeAlias :: Regular { name, .. } => {
596
+ format ! ( "-type {} exported: {}" , name, def. exported)
597
+ }
598
+ TypeAlias :: Opaque { name, .. } => {
599
+ format ! ( "-opaque {} exported: {}" , name, def. exported)
600
+ }
601
+ } ) )
602
+ . collect :: < Vec < _ > > ( )
603
+ . join ( "\n " ) ;
604
+ resolved. push ( '\n' ) ;
605
+ expect. assert_eq ( & resolved) ;
606
+ }
607
+
608
+ fn check_functions_by_id ( fixture : & str , expect : Expect ) {
609
+ let ( db, files) = TestDB :: with_many_files ( fixture) ;
610
+ let file_id = files[ 0 ] ;
611
+ let def_map = db. def_map ( file_id) ;
612
+ let mut resolved = def_map
613
+ . function_by_function_id
614
+ . values ( )
615
+ . map ( |def| {
616
+ format ! (
617
+ "fun {} exported: {}" ,
618
+ def. function. name,
619
+ def. exported && def_map. exported_functions. contains( & def. function. name) ,
586
620
)
587
621
} )
588
622
. chain ( def_map. types . values ( ) . map ( |def| match & def. type_alias {
@@ -785,4 +819,35 @@ bar() -> ok.
785
819
"# ] ] ,
786
820
)
787
821
}
822
+
823
+ #[ test]
824
+ fn multiple_mfas ( ) {
825
+ check_functions (
826
+ r#"
827
+ foo(A,B,C) -> {A,B,C}.
828
+ bar() -> ok.
829
+ foo(X,Y, Z) -> ok.
830
+ "# ,
831
+ expect ! [ [ r#"
832
+ fun foo/3 exported: false
833
+ fun bar/0 exported: false
834
+ "# ] ] ,
835
+ )
836
+ }
837
+
838
+ #[ test]
839
+ fn multiple_mfas_by_id ( ) {
840
+ check_functions_by_id (
841
+ r#"
842
+ foo(A,B,C) -> {A,B,C}.
843
+ bar() -> ok.
844
+ foo(X,Y, Z) -> ok.
845
+ "# ,
846
+ expect ! [ [ r#"
847
+ fun foo/3 exported: false
848
+ fun bar/0 exported: false
849
+ fun foo/3 exported: false
850
+ "# ] ] ,
851
+ )
852
+ }
788
853
}
0 commit comments