@@ -71,7 +71,7 @@ def run(self) -> None:
7171 console .rule ()
7272 if not env_utils .ensure_codeflash_api_key ():
7373 return
74-
74+ function_optimizer = None
7575 file_to_funcs_to_optimize : dict [Path , list [FunctionToOptimize ]]
7676 num_optimizable_functions : int
7777 (file_to_funcs_to_optimize , num_optimizable_functions ) = get_functions_to_optimize (
@@ -166,18 +166,7 @@ def run(self) -> None:
166166 function_optimizer = self .create_function_optimizer (
167167 function_to_optimize , function_to_optimize_ast , function_to_tests , validated_original_code [original_module_path ].source_code
168168 )
169- try :
170- best_optimization = function_optimizer .optimize_function ()
171- finally :
172- for test_file in function_optimizer .test_files .get_by_type (TestType .GENERATED_REGRESSION ).test_files :
173- test_file .instrumented_behavior_file_path .unlink (missing_ok = True )
174- test_file .benchmarking_file_path .unlink (missing_ok = True )
175- for test_file in function_optimizer .test_files .get_by_type (TestType .EXISTING_UNIT_TEST ).test_files :
176- test_file .instrumented_behavior_file_path .unlink (missing_ok = True )
177- test_file .benchmarking_file_path .unlink (missing_ok = True )
178- for test_file in function_optimizer .test_files .get_by_type (TestType .CONCOLIC_COVERAGE_TEST ).test_files :
179- test_file .instrumented_behavior_file_path .unlink (missing_ok = True )
180-
169+ best_optimization = function_optimizer .optimize_function ()
181170 if is_successful (best_optimization ):
182171 optimizations_found += 1
183172 else :
@@ -190,10 +179,20 @@ def run(self) -> None:
190179 elif self .args .all :
191180 logger .info ("✨ All functions have been optimized! ✨" )
192181 finally :
182+ if function_optimizer :
183+ for test_file in function_optimizer .test_files .get_by_type (TestType .GENERATED_REGRESSION ).test_files :
184+ test_file .instrumented_behavior_file_path .unlink (missing_ok = True )
185+ test_file .benchmarking_file_path .unlink (missing_ok = True )
186+ for test_file in function_optimizer .test_files .get_by_type (TestType .EXISTING_UNIT_TEST ).test_files :
187+ test_file .instrumented_behavior_file_path .unlink (missing_ok = True )
188+ test_file .benchmarking_file_path .unlink (missing_ok = True )
189+ for test_file in function_optimizer .test_files .get_by_type (TestType .CONCOLIC_COVERAGE_TEST ).test_files :
190+ test_file .instrumented_behavior_file_path .unlink (missing_ok = True )
191+ if function_optimizer .test_cfg .concolic_test_root_dir :
192+ shutil .rmtree (function_optimizer .test_cfg .concolic_test_root_dir , ignore_errors = True )
193193 if hasattr (get_run_tmp_file , "tmpdir" ):
194194 get_run_tmp_file .tmpdir .cleanup ()
195- if self .test_cfg .concolic_test_root_dir :
196- shutil .rmtree (self .test_cfg .concolic_test_root_dir , ignore_errors = True )
195+
197196
198197
199198def run_with_args (args : Namespace ) -> None :
0 commit comments