Skip to content

Commit b26b86c

Browse files
stepanchegfacebook-github-bot
authored andcommitted
Replace From EvalException with standalone function and mark function cold
Reviewed By: ndmitchell Differential Revision: D30887698 fbshipit-source-id: d6ea9bc75bb117d29e3d2220e06645b852b1a034
1 parent 64b1121 commit b26b86c

File tree

3 files changed

+17
-14
lines changed

3 files changed

+17
-14
lines changed

starlark/src/eval/compiler/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,17 @@ pub(crate) fn expr_throw<'v, T>(
188188
}
189189
}
190190

191-
impl From<EvalException<'_>> for anyhow::Error {
192-
fn from(x: EvalException) -> Self {
193-
match x {
194-
EvalException::Error(e) => e,
195-
EvalException::Break => anyhow!("Break statement used outside of a loop"),
196-
EvalException::Continue => anyhow!("Continue statement used outside of a loop"),
197-
EvalException::Return(..) => {
198-
anyhow!("Return statement used outside of a function call")
199-
}
191+
#[cold]
192+
#[inline(never)]
193+
pub(crate) fn throw_eval_exception<T>(x: EvalException<'_>) -> anyhow::Result<T> {
194+
Err(match x {
195+
EvalException::Error(e) => e,
196+
EvalException::Break => anyhow!("Break statement used outside of a loop"),
197+
EvalException::Continue => anyhow!("Continue statement used outside of a loop"),
198+
EvalException::Return(..) => {
199+
anyhow!("Return statement used outside of a function call")
200200
}
201-
}
201+
})
202202
}
203203

204204
pub(crate) struct Compiler<'a> {

starlark/src/eval/fragment/def.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
scope::{
2727
Captured, CstAssignIdent, CstExpr, CstParameter, CstStmt, ScopeId, ScopeNames,
2828
},
29-
Compiler, EvalException, StmtCompiled,
29+
throw_eval_exception, Compiler, EvalException, StmtCompiled,
3030
},
3131
fragment::expr::{ExprCompiled, ExprCompiledValue},
3232
runtime::{
@@ -510,7 +510,7 @@ impl<'v, V: ValueLike<'v>> DefGen<V> {
510510

511511
let ret = match res {
512512
Err(EvalException::Return(ret)) => ret,
513-
Err(e) => return Err(e.into()),
513+
Err(e) => return throw_eval_exception(e),
514514
Ok(_) => Value::new_none(),
515515
};
516516

starlark/src/eval/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ use gazebo::{cast, prelude::*};
2929
use std::{intrinsics::unlikely, mem};
3030

3131
use crate::{
32-
eval::compiler::scope::{CompilerAstMap, ScopeData},
32+
eval::compiler::{
33+
scope::{CompilerAstMap, ScopeData},
34+
throw_eval_exception,
35+
},
3336
values::docs::DocString,
3437
};
3538
pub(crate) use compiler::scope::ScopeNames;
@@ -157,7 +160,7 @@ impl<'v, 'a> Evaluator<'v, 'a> {
157160
match res {
158161
Ok(_) => Ok(Value::new_none()),
159162
Err(EvalException::Return(x)) => Ok(x),
160-
Err(e) => Err(e.into()),
163+
Err(e) => throw_eval_exception(e),
161164
}
162165
}
163166

0 commit comments

Comments
 (0)