@@ -998,7 +998,6 @@ def find_and_process_best_optimization(
998998 original_code_combined [explanation .file_path ] = self .function_to_optimize_source_code
999999 new_code_combined = new_helper_code .copy ()
10001000 new_code_combined [explanation .file_path ] = new_code
1001- < << << << feat - staging
10021001 self .process_review (
10031002 original_code_baseline ,
10041003 best_optimization ,
@@ -1012,71 +1011,85 @@ def find_and_process_best_optimization(
10121011 exp_type ,
10131012 original_helper_code ,
10141013 )
1015- == == == =
1016- if not self .args .no_pr :
1017- coverage_message = (
1018- original_code_baseline .coverage_results .build_message ()
1019- if original_code_baseline .coverage_results
1020- else "Coverage data not available"
1021- )
1022- generated_tests = remove_functions_from_generated_tests (
1023- generated_tests = generated_tests , test_functions_to_remove = test_functions_to_remove
1024- )
1025- original_runtime_by_test = (
1026- original_code_baseline .benchmarking_test_results .usable_runtime_data_by_test_case ()
1027- )
1028- optimized_runtime_by_test = (
1029- best_optimization .winning_benchmarking_test_results .usable_runtime_data_by_test_case ()
1030- )
1031- qualified_name = self .function_to_optimize .qualified_name_with_modules_from_root (self .project_root )
1032- # Add runtime comments to generated tests before creating the PR
1033- generated_tests = add_runtime_comments_to_generated_tests (
1034- generated_tests , original_runtime_by_test , optimized_runtime_by_test
1035- )
1036- generated_tests_str = "\n \n " .join (
1037- [test .generated_original_test_source for test in generated_tests .generated_tests ]
1038- )
1039- existing_tests = existing_tests_source_for (
1040- qualified_name ,
1041- function_to_all_tests ,
1042- test_cfg = self .test_cfg ,
1043- original_runtimes_all = original_runtime_by_test ,
1044- optimized_runtimes_all = optimized_runtime_by_test ,
1045- )
1046- if concolic_test_str :
1047- generated_tests_str += "\n \n " + concolic_test_str
1048-
1049- check_create_pr (
1050- original_code = original_code_combined ,
1051- new_code = new_code_combined ,
1052- explanation = explanation ,
1053- existing_tests_source = existing_tests ,
1054- generated_original_test_source = generated_tests_str ,
1055- function_trace_id = self .function_trace_id [:- 4 ] + exp_type
1056- if self .experiment_id
1057- else self .function_trace_id ,
1058- coverage_message = coverage_message ,
1059- git_remote = self .args .git_remote ,
1060- )
1061- if (
1062- self .args .all
1063- or env_utils .get_pr_number ()
1064- or self .args .replay_test
1065- or (self .args .file and not self .args .function )
1066- ):
1067- self .write_code_and_helpers (
1068- self .function_to_optimize_source_code ,
1069- original_helper_code ,
1070- self .function_to_optimize .file_path ,
1071- )
1072- else :
1073- # Mark optimization success since no PR will be created
1074- mark_optimization_success (
1075- trace_id = self .function_trace_id , is_optimization_found = best_optimization is not None
1076- )
1077- > >> >> >> main
1078- self .log_successful_optimization (explanation , generated_tests , exp_type )
1079- return best_optimization
1014+ self .log_successful_optimization (explanation , generated_tests , exp_type )
1015+ return best_optimization
1016+
1017+ def process_review (
1018+ self ,
1019+ original_code_baseline : OriginalCodeBaseline ,
1020+ best_optimization : BestOptimization ,
1021+ generated_tests : GeneratedTestsList ,
1022+ test_functions_to_remove : list [str ],
1023+ concolic_test_str : str | None ,
1024+ original_code_combined : dict [Path , str ],
1025+ new_code_combined : dict [Path , str ],
1026+ explanation : Explanation ,
1027+ function_to_all_tests : dict [str , set [FunctionCalledInTest ]],
1028+ exp_type : str ,
1029+ original_helper_code : dict [Path , str ],
1030+ ) -> None :
1031+ coverage_message = (
1032+ original_code_baseline .coverage_results .build_message ()
1033+ if original_code_baseline .coverage_results
1034+ else "Coverage data not available"
1035+ )
1036+
1037+ generated_tests = remove_functions_from_generated_tests (
1038+ generated_tests = generated_tests , test_functions_to_remove = test_functions_to_remove
1039+ )
1040+
1041+ original_runtime_by_test = original_code_baseline .benchmarking_test_results .usable_runtime_data_by_test_case ()
1042+ optimized_runtime_by_test = (
1043+ best_optimization .winning_benchmarking_test_results .usable_runtime_data_by_test_case ()
1044+ )
1045+
1046+ generated_tests = add_runtime_comments_to_generated_tests (
1047+ self .test_cfg , generated_tests , original_runtime_by_test , optimized_runtime_by_test
1048+ )
1049+
1050+ generated_tests_str = "\n \n " .join (
1051+ [test .generated_original_test_source for test in generated_tests .generated_tests ]
1052+ )
1053+ if concolic_test_str :
1054+ generated_tests_str += "\n \n " + concolic_test_str
1055+
1056+ existing_tests = existing_tests_source_for (
1057+ self .function_to_optimize .qualified_name_with_modules_from_root (self .project_root ),
1058+ function_to_all_tests ,
1059+ test_cfg = self .test_cfg ,
1060+ original_runtimes_all = original_runtime_by_test ,
1061+ optimized_runtimes_all = optimized_runtime_by_test ,
1062+ )
1063+
1064+ data = {
1065+ "original_code" : original_code_combined ,
1066+ "new_code" : new_code_combined ,
1067+ "explanation" : explanation ,
1068+ "existing_tests_source" : existing_tests ,
1069+ "generated_original_test_source" : generated_tests_str ,
1070+ "function_trace_id" : self .function_trace_id [:- 4 ] + exp_type
1071+ if self .experiment_id
1072+ else self .function_trace_id ,
1073+ "coverage_message" : coverage_message ,
1074+ }
1075+
1076+ if not self .args .no_pr and not self .args .staging_review :
1077+ data ["git_remote" ] = self .args .git_remote
1078+ check_create_pr (** data )
1079+ elif self .args .staging_review :
1080+ create_staging (** data )
1081+ else :
1082+ # Mark optimization success since no PR will be created
1083+ mark_optimization_success (
1084+ trace_id = self .function_trace_id , is_optimization_found = best_optimization is not None
1085+ )
1086+
1087+ if ((not self .args .no_pr ) or not self .args .staging_review ) and (
1088+ self .args .all or env_utils .get_pr_number () or (self .args .file and not self .args .function )
1089+ ):
1090+ self .write_code_and_helpers (
1091+ self .function_to_optimize_source_code , original_helper_code , self .function_to_optimize .file_path
1092+ )
10801093
10811094 def establish_original_code_baseline (
10821095 self ,
0 commit comments