@@ -22,11 +22,12 @@ use solar_parse::{
2222 } ,
2323 Parser ,
2424} ;
25- use solar_sema:: { hir :: Arena , ParsingContext } ;
25+ use solar_sema:: ParsingContext ;
2626use std:: {
2727 collections:: HashSet ,
2828 path:: { Path , PathBuf } ,
2929} ;
30+ use solar_sema:: thread_local:: ThreadLocal ;
3031
3132mod data;
3233mod deps;
@@ -74,7 +75,6 @@ impl Preprocessor<SolcCompiler> for TestOptimizerPreprocessor {
7475
7576 let sess = Session :: builder ( ) . with_buffer_emitter ( Default :: default ( ) ) . build ( ) ;
7677 let _ = sess. enter_parallel ( || -> solar_parse:: interface:: Result {
77- let hir_arena = Arena :: new ( ) ;
7878 let mut parsing_context = ParsingContext :: new ( & sess) ;
7979 // Set remappings into HIR parsing context.
8080 for remapping in & paths. remappings {
@@ -93,24 +93,27 @@ impl Preprocessor<SolcCompiler> for TestOptimizerPreprocessor {
9393 . collect_vec ( ) ;
9494 parsing_context. load_files ( & preprocessed_paths) ?;
9595
96- let hir = & parsing_context. parse_and_lower_to_hir ( & hir_arena) ?;
97- // Collect tests and scripts dependencies and identify mock contracts.
98- let deps = PreprocessorDependencies :: new (
99- & sess,
100- hir,
101- & preprocessed_paths,
102- & paths. paths_relative ( ) . sources ,
103- & paths. root ,
104- mocks,
105- ) ;
106- // Collect data of source contracts referenced in tests and scripts.
107- let data = collect_preprocessor_data ( & sess, hir, & deps. referenced_contracts ) ;
96+ let hir_arena = ThreadLocal :: new ( ) ;
97+ if let Some ( gcx) = parsing_context. parse_and_lower ( & hir_arena) ? {
98+ let hir = & gcx. get ( ) . hir ;
99+ // Collect tests and scripts dependencies and identify mock contracts.
100+ let deps = PreprocessorDependencies :: new (
101+ & sess,
102+ hir,
103+ & preprocessed_paths,
104+ & paths. paths_relative ( ) . sources ,
105+ & paths. root ,
106+ mocks,
107+ ) ;
108+ // Collect data of source contracts referenced in tests and scripts.
109+ let data = collect_preprocessor_data ( & sess, hir, & deps. referenced_contracts ) ;
108110
109- // Extend existing sources with preprocessor deploy helper sources.
110- sources. extend ( create_deploy_helpers ( & data) ) ;
111+ // Extend existing sources with preprocessor deploy helper sources.
112+ sources. extend ( create_deploy_helpers ( & data) ) ;
111113
112- // Generate and apply preprocessor source updates.
113- apply_updates ( sources, remove_bytecode_dependencies ( hir, & deps, & data) ) ;
114+ // Generate and apply preprocessor source updates.
115+ apply_updates ( sources, remove_bytecode_dependencies ( hir, & deps, & data) ) ;
116+ }
114117
115118 Ok ( ( ) )
116119 } ) ;
0 commit comments