From 6d31bb0d1929dca4d749b097adb52f5c0a223ea1 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 19 Oct 2021 20:16:36 +0800 Subject: [PATCH] Do not inline error path functions. --- CHANGELOG.md | 1 + src/error.rs | 6 +++--- src/error_parsing.rs | 2 +- src/fn_call.rs | 1 + src/packages/arithmetic.rs | 2 +- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef8a0f8c..2f97e900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Enhancements * `NativeCallContext::call_fn_dynamic_raw` is deprecated and `NativeCallContext::call_fn_raw` is added. * Array methods now avoid cloning as much as possible (although most predicates will involve cloning anyway if passed a closure). +* Inlining is disabled for error-path functions because, most of the time, the script fails completely when an error is encountered. Version 1.1.0 diff --git a/src/error.rs b/src/error.rs index adc7cf15..52c6fe3c 100644 --- a/src/error.rs +++ b/src/error.rs @@ -216,14 +216,14 @@ impl fmt::Display for EvalAltResult { } impl> From for EvalAltResult { - #[inline(always)] + #[inline(never)] fn from(err: T) -> Self { Self::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE) } } impl> From for Box { - #[inline(always)] + #[inline(never)] fn from(err: T) -> Self { EvalAltResult::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE).into() } @@ -444,7 +444,7 @@ impl EvalAltResult { } /// Consume the current [`EvalAltResult`] and return a new one with the specified [`Position`] /// if the current position is [`Position::None`]. - #[inline] + #[inline(never)] #[must_use] pub(crate) fn fill_position(mut self: Box, new_position: Position) -> Box { if self.position().is_none() { diff --git a/src/error_parsing.rs b/src/error_parsing.rs index 1094028c..66b740b6 100644 --- a/src/error_parsing.rs +++ b/src/error_parsing.rs @@ -266,7 +266,7 @@ impl fmt::Display for ParseErrorType { } impl From for ParseErrorType { - #[inline(always)] + #[inline(never)] fn from(err: LexError) -> Self { match err { LexError::StringTooLong(max) => { diff --git a/src/fn_call.rs b/src/fn_call.rs index 61911f74..56f26918 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -481,6 +481,7 @@ impl Engine { pos: Position, level: usize, ) -> RhaiResult { + #[inline(never)] fn make_error( name: String, fn_def: &crate::ast::ScriptFnDef, diff --git a/src/packages/arithmetic.rs b/src/packages/arithmetic.rs index 66c05978..f387d862 100644 --- a/src/packages/arithmetic.rs +++ b/src/packages/arithmetic.rs @@ -9,7 +9,7 @@ use std::prelude::v1::*; #[cfg(not(feature = "no_float"))] use num_traits::Float; -#[inline(always)] +#[inline(never)] pub fn make_err(msg: impl Into) -> Box { EvalAltResult::ErrorArithmetic(msg.into(), Position::NONE).into() }