1+ use std:: path:: PathBuf ;
2+
13use codegen_sdk_ast:: { Definitions , References } ;
24#[ cfg( feature = "serialization" ) ]
35use codegen_sdk_common:: serialize:: Cache ;
4- use codegen_sdk_cst:: File ;
56use codegen_sdk_resolution:: { Db , Scope } ;
67use indicatif:: { ProgressBar , ProgressStyle } ;
78
89use super :: discovery:: { FilesToParse , log_languages} ;
910use crate :: { ParsedFile , database:: CodegenDatabase , parser:: parse_file} ;
10- pub fn execute_op_with_progress < Database : Db + ?Sized + ' static , T : Send + Sync > (
11+ pub fn execute_op_with_progress <
12+ Database : Db + ?Sized + ' static ,
13+ Input : Send + Sync ,
14+ T : Send + Sync ,
15+ > (
1116 db : & Database ,
12- files : codegen_sdk_common:: hash:: FxHashSet < File > ,
17+ files : codegen_sdk_common:: hash:: FxHashSet < Input > ,
1318 name : & str ,
14- op : fn ( & Database , File ) -> T ,
19+ parallel : bool ,
20+ op : fn ( & Database , Input ) -> T ,
1521) -> Vec < T > {
1622 let multi = db. multi_progress ( ) ;
1723 let style = ProgressStyle :: with_template (
@@ -27,19 +33,35 @@ pub fn execute_op_with_progress<Database: Db + ?Sized + 'static, T: Send + Sync>
2733 . into_iter ( )
2834 . map ( |file| ( & pg, file, op) )
2935 . collect :: < Vec < _ > > ( ) ;
30- let results: Vec < T > = salsa:: par_map ( db, inputs, move |db, input| {
31- let ( pg, file, op) = input;
32- let res = op (
33- db,
34- #[ cfg( feature = "serialization" ) ]
35- & cache,
36- file,
37- ) ;
38- pg. inc ( 1 ) ;
39- res
40- } ) ;
36+ let results: Vec < _ > = if parallel {
37+ salsa:: par_map ( db, inputs, move |db, input| {
38+ let ( pg, file, op) = input;
39+ let res = op (
40+ db,
41+ #[ cfg( feature = "serialization" ) ]
42+ & cache,
43+ file,
44+ ) ;
45+ pg. inc ( 1 ) ;
46+ res
47+ } )
48+ } else {
49+ inputs
50+ . into_iter ( )
51+ . map ( |input| {
52+ let ( pg, file, op) = input;
53+ let res = op (
54+ db,
55+ #[ cfg( feature = "serialization" ) ]
56+ & cache,
57+ file,
58+ ) ;
59+ pg. inc ( 1 ) ;
60+ res
61+ } )
62+ . collect ( )
63+ } ;
4164 pg. finish ( ) ;
42- multi. remove ( & pg) ;
4365 results
4466}
4567// #[salsa::tracked]
@@ -50,7 +72,12 @@ pub fn execute_op_with_progress<Database: Db + ?Sized + 'static, T: Send + Sync>
5072// }
5173#[ salsa:: tracked]
5274fn parse_files_definitions_par ( db : & dyn Db , files : FilesToParse ) {
53- let _: Vec < _ > = execute_op_with_progress ( db, files. files ( db) , "Parsing Files" , |db, input| {
75+ let ids = files
76+ . files ( db)
77+ . iter ( )
78+ . map ( |input| codegen_sdk_common:: FileNodeId :: new ( db, input. path ( db) ) )
79+ . collect :: < codegen_sdk_common:: hash:: FxHashSet < _ > > ( ) ;
80+ let _: Vec < _ > = execute_op_with_progress ( db, ids, "Parsing Files" , true , |db, input| {
5481 let file = parse_file ( db, input. clone ( ) ) ;
5582 if let Some ( parsed) = file. file ( db) {
5683 #[ cfg( feature = "typescript" ) ]
@@ -62,12 +89,47 @@ fn parse_files_definitions_par(db: &dyn Db, files: FilesToParse) {
6289 if let ParsedFile :: Python ( parsed) = parsed {
6390 parsed. definitions ( db) ;
6491 parsed. references ( db) ;
65- codegen_sdk_python:: ast:: dependencies ( db, input) ;
92+ // let deps = codegen_sdk_python::ast::dependencies(db, input);
93+ // for dep in deps.dependencies(db).keys() {
94+ // codegen_sdk_resolution::ast::references_impl(db, dep);
95+ // }
6696 }
6797 }
6898 ( )
6999 } ) ;
70100}
101+ #[ salsa:: tracked]
102+ fn compute_dependencies_par ( db : & dyn Db , files : FilesToParse ) {
103+ let ids = files
104+ . files ( db)
105+ . iter ( )
106+ . map ( |input| codegen_sdk_common:: FileNodeId :: new ( db, input. path ( db) ) )
107+ . collect :: < codegen_sdk_common:: hash:: FxHashSet < _ > > ( ) ;
108+ let targets: codegen_sdk_common:: hash:: FxHashSet < ( PathBuf , String ) > =
109+ execute_op_with_progress ( db, ids, "Computing Dependencies" , true , |db, input| {
110+ let file = parse_file ( db, input. clone ( ) ) ;
111+ if let Some ( parsed) = file. file ( db) {
112+ #[ cfg( feature = "python" ) ]
113+ if let ParsedFile :: Python ( parsed) = parsed {
114+ let deps = codegen_sdk_python:: ast:: dependency_keys ( db, input) ;
115+ return deps
116+ . iter ( )
117+ . map ( |dep| ( dep. path ( db) . path ( db) . clone ( ) , dep. name ( db) . clone ( ) ) )
118+ . collect :: < Vec < _ > > ( ) ;
119+ }
120+ }
121+ Vec :: new ( )
122+ } )
123+ . into_iter ( )
124+ . flatten ( )
125+ . collect ( ) ;
126+ // let _: Vec<_> = execute_op_with_progress(db, targets, "Finding Usages", true, |db, input: (PathBuf, String)| {
127+ // let file_node_id = codegen_sdk_common::FileNodeId::new(db, input.0);
128+ // let fully_qualified_name = codegen_sdk_resolution::FullyQualifiedName::new(db, file_node_id, input.1);
129+ // codegen_sdk_python::ast::references_impl(db, fully_qualified_name);
130+ // });
131+ }
132+
71133pub fn parse_files < ' db > (
72134 db : & ' db CodegenDatabase ,
73135 #[ cfg( feature = "serialization" ) ] cache : & ' db Cache ,
@@ -89,6 +151,12 @@ pub fn parse_files<'db>(
89151 & cache,
90152 files_to_parse,
91153 ) ;
154+ compute_dependencies_par (
155+ db,
156+ #[ cfg( feature = "serialization" ) ]
157+ & cache,
158+ files_to_parse,
159+ ) ;
92160 #[ cfg( feature = "serialization" ) ]
93161 report_cached_count ( cached, & files_to_parse. files ( db) ) ;
94162}
0 commit comments