From 92174471135b5f41cfa6a54bb61b0e5933271d7d Mon Sep 17 00:00:00 2001 From: Edwin Smith Date: Mon, 21 Mar 2022 11:10:08 -0700 Subject: [PATCH] do not use std::panic::catch_unwind Summary: Recovering from ad-hoc panics is an anti-pattern that can lead to undefined behavior. We need to be careful removing catch_unwinds() from production code since it could be papering over real bugs, but it should be safe to start with `hh_compile`. While I'm here, remove some dead code. Reviewed By: aorenste Differential Revision: D34999905 fbshipit-source-id: 28b7e617db201e25db9af65103855dce91bda5d9 --- hphp/hack/src/hh_compile/compile.rs | 30 +---------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/hphp/hack/src/hh_compile/compile.rs b/hphp/hack/src/hh_compile/compile.rs index 891a5ba9317ff7..796781217d40db 100644 --- a/hphp/hack/src/hh_compile/compile.rs +++ b/hphp/hack/src/hh_compile/compile.rs @@ -221,7 +221,7 @@ fn process_single_file_impl( Ok((output, profile)) } -fn process_single_file_with_retry( +pub(crate) fn process_single_file( opts: &SingleFileOpts, filepath: PathBuf, content: Vec, @@ -234,20 +234,6 @@ fn process_single_file_with_retry( })? } -pub(crate) fn process_single_file( - opts: &SingleFileOpts, - filepath: PathBuf, - content: Vec, -) -> Result<(Vec, Profile)> { - match std::panic::catch_unwind(|| process_single_file_with_retry(opts, filepath, content)) { - Ok(r) => r, - Err(panic) => match panic.downcast::() { - Ok(msg) => Err(anyhow!("panic: {}", msg)), - Err(_) => Err(anyhow!("panic: unknown")), - }, - } -} - fn assert_regular_file(filepath: impl AsRef) { let filepath = filepath.as_ref(); if !filepath.is_file() { @@ -276,20 +262,6 @@ impl Config { ret } - #[allow(dead_code)] // will be used if --daemon (by HHVM) - fn with_merged( - &mut self, - json: String, - cli_args: &[String], - f: impl FnOnce(&Options) -> T, - ) -> T { - self.jsons.push(json); - let hhbc_options = self.to_options(cli_args); - let ret = f(&hhbc_options); - self.jsons.pop(); - ret - } - fn to_options(&self, cli_args: &[String]) -> Options { Options::from_configs(&self.jsons, cli_args).unwrap() }